package com.lg.cms.shiro.filter;

import org.apache.shiro.web.filter.authz.RolesAuthorizationFilter;
import org.apache.shiro.web.util.WebUtils;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @Description: cms
 * @Author: wuyuhang
 * @create: 2020-10-02 17:04
 */
public class RoleFilter extends RolesAuthorizationFilter {
    private String userLoginUrl = "/login";
    private String superUserLoginUrl = "/admin/login";

    @Override
    protected void redirectToLogin(ServletRequest request, ServletResponse response) throws IOException {
        HttpServletRequest httpServletRequest = (HttpServletRequest) request;
        String url = httpServletRequest.getRequestURI();
        if(url.contains("admin")){
            WebUtils.issueRedirect(request, response, superUserLoginUrl);
        }else{
            WebUtils.issueRedirect(request, response, userLoginUrl);
        }
    }
}